package org.jeecg.modules.meter.service.impl;

import net.bytebuddy.asm.Advice;
import org.jeecg.modules.meter.entity.MeterSmsLevel;
import org.jeecg.modules.meter.entity.MeterSmsSend;
import org.jeecg.modules.meter.mapper.MeterSmsLevelMapper;
import org.jeecg.modules.meter.mapper.MeterSmsSendMapper;
import org.jeecg.modules.meter.service.IMeterSmsSendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 仪表短信提醒
 * @Author: jeecg-boot
 * @Date:   2019-12-05
 * @Version: V1.0
 */
@Service
public class MeterSmsSendServiceImpl extends ServiceImpl<MeterSmsSendMapper, MeterSmsSend> implements IMeterSmsSendService {


    @Autowired
    private MeterSmsSendMapper meterSmsSendMapper;

    @Autowired
    private MeterSmsLevelMapper meterSmsLevelMapper;

    @Override
    public List<MeterSmsSend> findSmsListByMeterId(String meterId) {
        List<MeterSmsSend> list =  meterSmsSendMapper.findSmsListByMeterId(meterId);
        if (list.size() > 0 ){
            MeterSmsLevel meterSmsLevel = meterSmsLevelMapper.selectMeterSmsLevel(list.get(0).getProjectId(), list.get(0).getMeterType());
            if (meterSmsLevel != null){
                for (MeterSmsSend smsSend:list){
                    smsSend.setLevelType(meterSmsLevel.getType());
                    if (smsSend.getLevel() == 1) {
                        smsSend.setLevelDegree(meterSmsLevel.getV1().toString());
                    } else if (smsSend.getLevel() == 2){
                        smsSend.setLevelDegree(meterSmsLevel.getV2().toString());
                    } else if (smsSend.getLevel() == 3){
                        smsSend.setLevelDegree(meterSmsLevel.getV3().toString());
                    } else if (smsSend.getLevel() == 4){
                        smsSend.setLevelDegree(meterSmsLevel.getV4().toString());
                    } else {
                        smsSend.setLevelDegree("0");
                    }
                }
            }
        }
        return list;
    }

    @Override
    public void updateOverStatus(List<String> updateList) {
        meterSmsSendMapper.updateOverStatus(updateList);
    }
}
